/**
 * 员工工资管理初始化
 */
var Payroll = {
    id: "PayrollTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
Payroll.initColumn = function () {
    return [
			[
			{field: 'selectItem', radio: true,colspan: 1,rowspan: 4,width:'36px'},
            {title: '编号', field: 'usercode', visible: true, align: 'center', valign: 'middle',width:'60px',colspan: 1,rowspan: 4},
            {title: '名称', field: 'username', visible: true, align: 'center', valign: 'middle',width:'70px',colspan: 1,rowspan: 4},
            {title: '部门', field: 'platformName', visible: true, align: 'center', valign: 'middle',width:'70px',colspan: 1,rowspan: 4},
			{title: '工资月份', field: 'payTime', visible: true, align: 'center', valign: 'middle',width:'100px',colspan: 1,rowspan: 4},
            {title: '入职时间', field: 'entryTime', visible: true, align: 'center', valign: 'middle',width:'100px',colspan: 1,rowspan: 4},
            {title: '底薪', field: 'basicSalary',sortable: true,halign:'center',  valign: 'middle',width:'100px',colspan: 1,rowspan: 4},
            {title: '奖金', field: 'bonus', visible: true,halign:'center',  valign: 'middle',width:'100px',colspan: 1,rowspan: 4},
			{title: '应发栏',valign:"middle",align:"center",colspan: 7,rowspan: 1,width:'800px'},
			{title: '扣款栏',valign:"middle",align:"center",colspan: 7,rowspan: 2,width:'800px'},
			{title: '应发工资',valign:"middle",align:"center",colspan: 2,rowspan: 2,width:'200px'},
			{title: '房补', field: 'roomSupplement', visible: true, halign:'center',  valign: 'middle',width:'100px',colspan: 1,rowspan: 4},
			{title: '实发piso', field: 'realPiso', visible: true, halign:'center',  valign: 'middle',width:'100px',colspan: 1,rowspan: 4},
            {title: '备注', field: 'remarks', visible: true, align: 'center', valign: 'middle',width:'100px',colspan: 1,rowspan: 4},
			],
			[
			
			{title: '基本工资',valign:"middle",align:"center",colspan: 3,rowspan: 1,width:'400px'},
			{title: '业绩奖金', field: 'performanceBonus', visible: true, halign:'center',  valign: 'middle',width:'100px',colspan: 1,rowspan: 3},
            {title: '提成', field: 'commission', visible: true, halign:'center',  valign: 'middle',width:'100px',colspan: 1,rowspan: 3},
            {title: '无休奖金', field: 'norepairBonus', visible: true, halign:'center',  valign: 'middle',width:'100px',colspan: 1,rowspan: 3},
            {title: '其他补贴', field: 'otherSubsidies', visible: true, halign:'center',  valign: 'middle',width:'100px',colspan: 1,rowspan: 3},
			],
			[
			
			{title: '出勤天数', field: 'attendanceDays', visible: true, align: 'center', valign: 'middle',width:'100px',colspan: 1,rowspan: 2},
            {title: '实际底薪', field: 'actualBasicSalary', visible: true, halign:'center',  valign: 'middle',width:'100px',colspan: 1,rowspan: 2},
            {title: '实际奖金', field: 'actualBonus', visible: true, halign:'center',  valign: 'middle',width:'100px',colspan: 1,rowspan: 2},
			{title: '请假栏',valign:"middle",align:"center",colspan: 2,rowspan: 1},
			{title: '迟到栏',valign:"middle",align:"center",colspan: 2,rowspan: 1},
			{title: '其他扣款', field: 'otherDeduction', visible: true,halign:'center',  valign: 'middle',width:'100px',colspan: 1,rowspan: 2},
			{title: '预支金额',valign:"middle",align:"center",colspan: 2,rowspan: 1},
			{title: '实发人民币', field: 'realRmb', visible: true, halign:'center',  valign: 'middle',width:'100px',colspan: 1,rowspan: 2},
            {title: '应发piso', field: 'sendPsio', visible: true, halign:'center',  valign: 'middle',width:'100px',colspan: 1,rowspan: 2},
			],
            [
			
		    {title: '请假天数', field: 'leaveDays', visible: true, align: 'center', valign: 'middle',width:'100px'},
            {title: '请假扣款', field: 'leaveDeduction', visible: true, halign:'center',  valign: 'middle',width:'100px'},
            {title: '迟到次数', field: 'lateArrivals', visible: true, align: 'center', valign: 'middle',width:'100px'},
            {title: '迟到扣款', field: 'letaDeduction', visible: true, halign:'center',  valign: 'middle',width:'100px'},           
            {title: '预支piso', field: 'advancePiso', visible: true, halign:'center',  valign: 'middle',width:'100px'},
            {title: '预支人民币', field: 'advanceRmb', visible: true, halign:'center',  valign: 'middle',width:'100px'}
			]
          
           

            

    ];
};

/**
 * 检查是否选中
 */
Payroll.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        Payroll.seItem = selected[0];
        return true;
    }
};

Payroll.checkPayTime = function(){
    var payTime =  $("#payTime").val();
    if (payTime==null||payTime==""){
        Feng.info("请选择要导出的工资表时间");
        return false;
    } else {
        return true;
    }
}

/**
 * 打开文件上传选择框
 */
Payroll.upLoadFile = function(){
    var index = layer.open({
        type:2,
        title:'请选择要上传的文件',
        fix:false,
        maxmin:true,
        content: Feng.ctxPath + '/payroll/payroll_upload'

    });
    this.layerIndex = index;
}

/**
 * 点击添加员工工资
 */
Payroll.openAddPayroll = function () {
    var index = layer.open({
        type: 2,
        title: '添加员工工资',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/payroll/payroll_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看员工工资详情
 */
Payroll.openPayrollDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '员工工资详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/payroll/payroll_update/' + Payroll.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除员工工资
 */
Payroll.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/payroll/delete", function (data) {
            Feng.success("删除成功!");
            Payroll.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("payrollId",this.seItem.id);
        ajax.start();
    }
};



/**
 * 导出
 */
Payroll.exportPayroll = function () {
    if (this.checkPayTime()) {
        window.location.href = "/payroll/load?payTime=" + $("#payTime").val();
    }


};

/**
 * 导出模板
 */
Payroll.exportModel = function () {
        window.location.href = "/payroll/download";


};

/**
 * 点击添导出工资表
 */
Payroll.openLoadPayroll = function () {
    var index = layer.open({
        type: 2,
        title: '请选择导出工资表时间',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/payroll/payroll_load'
    });
    this.layerIndex = index;
};

/**
 * 查询员工工资列表
 */
Payroll.search = function () {
    var queryData = {};
    queryData['payTime'] = $("#payTime").val();
	queryData['platform'] = $("#platform").val();
    Payroll.table.refresh({query: queryData});
};


Payroll.resetSearch = function () {
    $("#platform").val("");
    $("#payTime").val("");
}

/**
 * 查询表单提交参数对象
 * @returns {{}}
 */
Payroll.formParams = function() {
    var queryData = {};
    queryData['payTime'] = $("#payTime").val();
	queryData['platform'] = $("#platform").val();
    return queryData;
}

$(function () {
    var defaultColunms = Payroll.initColumn();
    var table = new BSTable(Payroll.id, "/payroll/list", defaultColunms,Payroll);
	table.setPaginationType("server");
    table.setQueryParams(Payroll.formParams());
	table.setShowColumns(false);
	table.setShowRefresh(false);
	table.height=800;
    Payroll.table = table.init();
	//添加表头
	$(".fixed-table-toolbar").after("<div style='text-align: center;vertical-align: middle;font-size: 22px;color: #6979d7;font-weight: bold;'> 工资表</div>");
});
